<?php

    session_start();

    $error = 0;
    $errormessage = '';
    if (isset($_GET['error'])) {
        $error = $_GET['error'];
    }
    if ($error != '0') {
        $error = 1;
        $errormessage = 'test error message';
    }

    $data = '';
    $photoid = $_GET['photoid'];

    require('connect.php');
    $query_set = "SELECT IFNULL( AVG( rating ) , 0 ) rating 
    FROM rating
    WHERE photoid ='$photoid'";
    $rows = array();
    $res = mysql_query($query_set) or die(mysql_error());
    while($r = mysql_fetch_assoc($res)) {
        $rows[] = $r;
    }
    $data = $rows[0]['rating'];

    $ajaxresult = (object) array('error' => $error, 'errormessage' => $errormessage, 'data' => $data);
    echo json_encode($ajaxresult);
    mysql_close($connection);

?>